
import LanguageMngTs from "../Managers/LanguageMngTs";

cc.Class({
    extends: cc.Component,

    properties: {
        bottomNode:{
            default:null,
            type:cc.Node,
        },

        bottomSprite:{
            default:null,
            type:cc.Sprite
        },

        frameRed:{
            default:null,
            type:cc.SpriteFrame,
        },

        frameGreen:{
            default:null,
            type:cc.SpriteFrame,
        },

        frameYellow:{
            default:null,
            type:cc.SpriteFrame,
        },

        frameBlue:{
            default:null,
            type:cc.SpriteFrame,
        },

        labelType:{
            default:null,
            type:cc.Label
        },

        bottomRect:{
            default:null,
            type:cc.Node,
        }
    },

    // LIFE-CYCLE CALLBACKS:

    // onLoad () {},

    start () {

    },

    update (dt) {

    },

    showBottom:function (botObj) {

        let width = botObj.width
        let typeObj = botObj.type
        let truePure = typeObj.pure
        let isPure = botObj.isGreen
        let group = botObj.pokers

        this.bottomNode.width = width
        this.bottomRect.width = width


        let groupType = typeObj.type
        isPure = isPure ? isPure : typeObj.pure
        if(!groupType && groupType !== cc.gg.enumConfig.SeperateType.NONE)
            return

        if(groupType === cc.gg.enumConfig.SeperateType.INVALID){
            this.bottomNode.active = true
            this.labelType.node.active = true

            this.bottomSum = cc.gg.sortUtil.GET_CARDS_SUM(group)
            let strInvalid = LanguageMngTs.getSentence(59) //Invalid
            this.labelType.string = strInvalid+" ("+this.bottomSum+")"
            this.bottomSprite.spriteFrame = this.frameRed
        }else if(groupType === cc.gg.enumConfig.SeperateType.SET){
            this.bottomNode.active = true
            this.labelType.node.active = true

            this.bottomSum = cc.gg.sortUtil.GET_CARDS_SUM(group)
            let string = LanguageMngTs.getSentence(82) //Set
            if(!isPure) string += " ("+this.bottomSum+")"
            this.labelType.string = string
            this.bottomSprite.spriteFrame = isPure ? this.frameBlue : this.frameYellow
        }
        else if(groupType === cc.gg.enumConfig.SeperateType.ALL_MIX){
            this.bottomNode.active = true
            this.labelType.node.active = false
            this.bottomSum = 0

            this.bottomSprite.spriteFrame = isPure ? this.frameBlue : this.frameYellow
        }
        else if(groupType === cc.gg.enumConfig.SeperateType.NONE){
            this.bottomNode.active = true
            this.labelType.node.active = false
            this.bottomSum = cc.gg.sortUtil.GET_CARDS_SUM(group)

            this.bottomSprite.spriteFrame = this.frameRed
        }else if(groupType === cc.gg.enumConfig.SeperateType.SEQUENCE){
            this.bottomNode.active = true
            this.labelType.node.active = true

            this.bottomSum = cc.gg.sortUtil.GET_CARDS_SUM(group)
            let string = truePure ? LanguageMngTs.getSentence(80) : LanguageMngTs.getSentence(61)   //Pure Sequence : Sequence
            if(!isPure) string += " ("+this.bottomSum + ")"
            this.labelType.string = string

            this.bottomSprite.spriteFrame = isPure ? this.frameGreen : this.frameYellow
        }else {
            cc.error("Unknown group type!")
            return
        }
    },


});
